Quick start
This example calculates the prayer times for Jakarta on 12 July 2026 using the
KEMENAG (Indonesia) method and prints each time as HH:MM.
The program
#define PRAYERTIMES_IMPLEMENTATION
#include "prayertimes.h"
#include <stdio.h>
int main(void) {
// 1. Pick a calculation method from the built-in catalogue.
const MethodParams *params = method_params_get(CALC_KEMENAG);
// 2. Compute the times for a date, location and UTC offset.
struct PrayerTimes t = calculate_prayer_times(
2026, 7, 12, // year, month, day
-6.2088, 106.8456, // latitude, longitude (Jakarta)
7.0, // UTC+7 (numeric offset in hours)
params);
// 3. Format the results. Times come back as decimal hours.
char buf[16];
format_time_hm(t.fajr, buf, sizeof buf); printf("Fajr %s\n", buf);
format_time_hm(t.dhuhr, buf, sizeof buf); printf("Dhuhr %s\n", buf);
format_time_hm(t.asr, buf, sizeof buf); printf("Asr %s\n", buf);
format_time_hm(t.maghrib, buf, sizeof buf); printf("Maghrib %s\n", buf);
format_time_hm(t.isha, buf, sizeof buf); printf("Isha %s\n", buf);
return 0;
}
Build and run
cc example.c -lm -o example
./example
Fajr 04:44
Dhuhr 12:01
Asr 15:23
Maghrib 17:54
Isha 19:09
Times depend on the calculation method, the location and the offset. Change any of them and the output changes.
Letting the library resolve the time zone
In the example above the UTC offset (7.0) is hard-coded. If you would rather
have the offset resolved from an IANA time zone, with daylight saving handled
automatically, include the optional timezone.h helper.
timezone.h must be included before any system header in that translation
unit, because it sets a feature-test macro that glibc reads the first time
<features.h> is pulled in. <time.h> is the obvious one, but prayertimes.h
includes <math.h>, which is enough to lock the setting in. Put timezone.h
first and the order can never be wrong.
Getting this wrong is silent under the default gnu11 dialect and a compile
error under -std=c11.
#define MUSLIM_TIMEZONE_IMPLEMENTATION
#include "timezone.h" // must come before any system header
#define PRAYERTIMES_IMPLEMENTATION
#include "prayertimes.h"
#include <time.h>
#include <stdio.h>
int main(void) {
time_t when = time(NULL);
double offset;
if (parse_timezone_offset("Asia/Jakarta", when, &offset) != 0) {
fprintf(stderr, "cannot resolve time zone\n");
return 1;
}
const MethodParams *params = method_params_get(CALC_KEMENAG);
struct PrayerTimes t = calculate_prayer_times(
2026, 7, 12, -6.2088, 106.8456, offset, params);
char buf[16];
format_time_hm(t.dhuhr, buf, sizeof buf);
printf("Dhuhr %s\n", buf);
return 0;
}
See the API reference for the full list of types and functions.